package com.example._03vehicle.base.interceptors;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("进入登录的拦截方法");
        //获取会话中的参数，session的用户标识uservo，判断是否为空，为空则重定向到登录页面，不为空则放行
        if(request.getSession().getAttribute("user")==null){
            response.sendRedirect("/login.html");
            return false;
        }
        else { return true;}

    }
}
